
/****************************************************************************/
/*Copyright (c) 2011, Florent DEVILLE.                                      */
/*All rights reserved.                                                      */
/*                                                                          */
/*Redistribution and use in source and binary forms, with or without        */
/*modification, are permitted provided that the following conditions        */
/*are met:                                                                  */
/*                                                                          */
/* - Redistributions of source code must retain the above copyright         */
/*notice, this list of conditions and the following disclaimer.             */
/* - Redistributions in binary form must reproduce the above                */
/*copyright notice, this list of conditions and the following               */
/*disclaimer in the documentation and/or other materials provided           */
/*with the distribution.                                                    */
/* - The names of its contributors cannot be used to endorse or promote     */
/*products derived from this software without specific prior written        */
/*permission.                                                               */
/* - The source code cannot be used for commercial purposes without         */ 
/*its contributors' permission.                                             */
/*                                                                          */
/*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       */
/*"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT         */
/*LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS         */
/*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE            */
/*COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,       */
/*INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,      */
/*BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;          */
/*LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER          */
/*CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT        */
/*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN         */
/*ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE           */
/*POSSIBILITY OF SUCH DAMAGE.                                               */
/****************************************************************************/

#include "GRTILight.h"
//#include <QGLWidget>
#include <QtOpenGL\qgl.h>
#include "GRTMemoryLeak.h"
//post render function
void GRTILight::postRender(){}

//constructor
GRTILight::GRTILight() : GRTMovable(), _typeOfLight(LT_NONE)
{
	_movableType = MT_LIGHT;

	_material.setAmbient(0, 0, 0, 1);
	_material.setDiffuse(1, 1, 1, 1);
	_material.setSpecular(1, 1, 1, 1);
}

//constructor
GRTILight::GRTILight(LIGHTTYPE type) : GRTMovable(), _typeOfLight(type)
{
	_movableType = MT_LIGHT;

	_material.setAmbient(0, 0, 0, 1);
	_material.setDiffuse(1, 1, 1, 1);
	_material.setSpecular(1, 1, 1, 1);
}

//destructor
GRTILight::~GRTILight()
{}

//draw the geometry
void GRTILight::draw()
{
	preRender();
	Render();
	postRender();
}

//get the geometry type
LIGHTTYPE GRTILight::getType() const
{
	return _typeOfLight;
}

//pre render function
void GRTILight::preRender()
{
	//store current matrix
	glPushMatrix();

	//apply translation
	glTranslatef(_translate.x, _translate.y, _translate.z);
	
	//apply rotations
	glRotatef(_rotate.x, 1, 0, 0);

	glRotatef(_rotate.y, 0, 1, 0);

	glRotatef(_rotate.z, 0, 0, 1);

	//apply scale
	glScalef(_scale.x, _scale.y, _scale.z);
}

//set the scaling factors
void GRTILight::setScale(const RTVector3f& /*s*/)
{
	return;
}

//add the vector as scale components
void GRTILight::scale(const RTVector3f& /*s*/)
{
	return;
}

//add the orientation
void GRTILight::rotate(const RTVector3f& /*rotate*/){}

//set the rotation angles
void GRTILight::setRotation(const RTVector3f& /*r*/){}

//draw as in render
void GRTILight::drawAsRender()
{
	//preRender();
	//postRender();
}

//get the material object
GRTMaterial& GRTILight::getMaterial()
{
	return _material;
}